{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f141fa45-10e5-4b13-9ba3-7552baa0df4c",
   "metadata": {},
   "source": [
    "# Neo4j & ChatGLM-6B 问答运行测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "08eb0ec3-6eac-4dc0-8960-b7c8bf488eec",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Defaulting to user installation because normal site-packages is not writeable\n",
      "Requirement already satisfied: zhipuai in c:\\users\\linqu\\appdata\\roaming\\python\\python310\\site-packages (1.0.7)\n",
      "Requirement already satisfied: dataclasses in c:\\users\\linqu\\appdata\\roaming\\python\\python310\\site-packages (from zhipuai) (0.6)\n",
      "Requirement already satisfied: PyJWT in c:\\users\\linqu\\appdata\\roaming\\python\\python310\\site-packages (from zhipuai) (2.7.0)\n",
      "Requirement already satisfied: cachetools in c:\\users\\linqu\\appdata\\roaming\\python\\python310\\site-packages (from zhipuai) (5.3.0)\n",
      "Requirement already satisfied: requests in c:\\users\\linqu\\appdata\\roaming\\python\\python310\\site-packages (from zhipuai) (2.28.2)\n",
      "Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\\programdata\\miniconda3\\lib\\site-packages (from requests->zhipuai) (1.26.14)\n",
      "Requirement already satisfied: idna<4,>=2.5 in c:\\programdata\\miniconda3\\lib\\site-packages (from requests->zhipuai) (3.4)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in c:\\programdata\\miniconda3\\lib\\site-packages (from requests->zhipuai) (2022.12.7)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\programdata\\miniconda3\\lib\\site-packages (from requests->zhipuai) (2.0.4)\n"
     ]
    }
   ],
   "source": [
    "!pip install zhipuai"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa0c41f7-a9c2-43bd-b01c-3376fe4b50d3",
   "metadata": {},
   "source": [
    "## ChatGLM模型API申请"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fbc3c7f7-186e-4cc2-bf94-6c5633663ce4",
   "metadata": {},
   "source": [
    "智谱AI可免费申请api使用，详情地址请到官网: https://open.bigmodel.cn/"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c2e8fc2-c2b9-4356-902e-637c644e31d5",
   "metadata": {
    "tags": []
   },
   "source": [
    "申请完成以后修改替换runner.py 中的 `zhipuai.api_key = \"-\"` 值。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bc5bd2c5-666f-4275-9b5c-573768d9d69d",
   "metadata": {},
   "source": [
    "### 输入问题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "39e9f5d0-3b06-4897-9b50-27719c2a7f26",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "question = '肺气肿不能吃什么'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e12406cd-adbe-4625-a03c-39f9e566ea96",
   "metadata": {},
   "source": [
    "### ChatGLM-6B模型回答"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "87571136-dd22-4147-8977-b8d61c39f9b2",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from runner import Runner"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2ecfa231-c13a-4bf1-9134-7674380d39b5",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "glm = Runner()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e2fb6ec8-b45c-4a8c-8b10-1b5f28e7da36",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"肺气肿患者应避免食用以下食物：圆白菜;带鱼;海虾;羊肉 (瘦)。\""
     ]
    }
   ],
   "source": [
    "answer =  glm.ask('肺气肿不能吃什么')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8d4aeb26-1bd6-4882-8fb7-6f1f250be91c",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"肺气肿患者应避免食用以下食物：圆白菜;带鱼;海虾;羊肉 (瘦)。\"\n"
     ]
    }
   ],
   "source": [
    "print(answer)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
